package com.fysports.web.model.user;

import com.google.common.collect.Maps;
import com.jfinal.log.Log;
import com.fysports.framework.kit.security.MD5Kit;
import com.fysports.web.kit.commons.StringKit;
import com.fysports.web.model.BaseModel;

import java.util.Date;
import java.util.Map;


/**
 * Created by konbluesky
 * Date : 14-8-13 上午10:55
 * Project : JdmData_WebServer
 */
public class BizUser extends BaseModel<BizUser> {
    private static Log log = Log.getLog(BizUser.class);
    public final static BizUser dao = new BizUser();
    /*数据库字段静态变量*/
    /** memberid  会员ID-生成规则待定 */
    public final static String COL_MEMBERID="memberid";
    /** pwd  登录密码 */
    public final static String COL_PWD="pwd";
    /** wxunionid  微信生成ID */
    public final static String COL_WXUNIONID="wxunionid";
    /** memtype  普通客户1分销商户2种子商户3 */
    public final static String COL_MEMTYPE="memtype";
    /** realname  真实姓名 */
    public final static String COL_REALNAME="realname";
    /** name  昵称 */
    public final static String COL_NAME="name";
    /** idcard  身份证号码 */
    public final static String COL_IDCARD="idcard";
    /** phone  手机号码 */
    public final static String COL_PHONE="phone";
    /** headimg  用户头像存放路径 */
    public final static String COL_HEADIMG="headimg";
    /** rankuuid  会员等级uuid */
    public final static String COL_RANKUUID="rankuuid";
    /** status  是否认证1已认证0未认证 */
    public final static String COL_STATUS="status";
    /** gender  1男，0女 */
    public final static String COL_GENDER="gender";
    /** remark   */
    public final static String COL_REMARK="remark";


    public BizUser() {
        if (this.getStr(COL_UUID) == null || this.getStr(COL_UUID).length() == 0) {
            this.set(COL_UUID, generateUUID());
        }
    }


    /**
     * 验证用户登录
     *
     * @param loginid
     * @param pwd
     * @param ismd5   是否为加密文
     * @return
     */
    public BizUser login(String loginid, String pwd, boolean ismd5) {
        if (StringKit.isBlank(loginid) || StringKit.isBlank(pwd))
            return null;
        Map<String, Object> params = Maps.newHashMap();
//        params.put(COL_LOGINID, loginid);
        /*默认为有效用户*/
        params.put(COL_LIVEFLAG, 1);
        if (ismd5) {//如是加密字段直接比对
            params.put(COL_PWD, pwd);
        }
        else {//加密后比对
            params.put(COL_PWD, MD5Kit.get32MD5(pwd));
        }
        return searchFirst(params);
    }


    public String getMemberid(){
        return this.getStr(COL_MEMBERID);
    }
    public void setMemberid(String memberid){
        this.set(COL_MEMBERID,memberid);
    }
    public String getPwd(){
        return this.getStr(COL_PWD);
    }
    public void setPwd(String pwd){
        this.set(COL_PWD,pwd);
    }
    public String getWxunionid(){
        return this.getStr(COL_WXUNIONID);
    }
    public void setWxunionid(String wxunionid){
        this.set(COL_WXUNIONID,wxunionid);
    }
    public String getMemtype(){
        return this.getStr(COL_MEMTYPE);
    }
    public void setMemtype(String memtype){
        this.set(COL_MEMTYPE,memtype);
    }
    public String getRealname(){
        return this.getStr(COL_REALNAME);
    }
    public void setRealname(String realname){
        this.set(COL_REALNAME,realname);
    }
    public String getName(){
        return this.getStr(COL_NAME);
    }
    public void setName(String name){
        this.set(COL_NAME,name);
    }
    public String getIdcard(){
        return this.getStr(COL_IDCARD);
    }
    public void setIdcard(String idcard){
        this.set(COL_IDCARD,idcard);
    }
    public String getPhone(){
        return this.getStr(COL_PHONE);
    }
    public void setPhone(String phone){
        this.set(COL_PHONE,phone);
    }
    public String getHeadimg(){
        return this.getStr(COL_HEADIMG);
    }
    public void setHeadimg(String headimg){
        this.set(COL_HEADIMG,headimg);
    }
    public String getRankuuid(){
        return this.getStr(COL_RANKUUID);
    }
    public void setRankuuid(String rankuuid){
        this.set(COL_RANKUUID,rankuuid);
    }
    public Boolean getisStatus(){
        return this.getBoolean(COL_STATUS);
    }
    public void setStatus(Boolean status){
        this.set(COL_STATUS,status);
    }
    public String getGender(){
        return this.getStr(COL_GENDER);
    }
    public void setGender(String gender){
        this.set(COL_GENDER,gender);
    }
    public String getLiveflag(){
        return this.getStr(COL_LIVEFLAG);
    }
    public void setLiveflag(String liveflag){
        this.set(COL_LIVEFLAG,liveflag);
    }
    public Date getCreatetime(){
        return this.getDate(COL_CREATETIME);
    }
    public void setCreatetime(Date createtime){
        this.set(COL_CREATETIME,createtime);
    }
    public String getRemark(){
        return this.getStr(COL_REMARK);
    }
    public void setRemark(String remark){
        this.set(COL_REMARK,remark);
    }

}
